﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using NJamb.Specifications;
using Stile.Patterns.SelfDescribingPredicates;
using Stile.Patterns.SelfDescribingPredicates.Evaluators;
using Stile.Readability;
#endregion

namespace NJamb.Parser.SpecificationBuilders.SubjectIs.Extensions
{
    public static class IsStringExtensions
    {
        public static TSpecifies NullOrEmpty<TSpecifies>(this IFluentIs<string, TSpecifies> collaboratingIs)
            where TSpecifies : class, ISpecification<string>
        {
            VerbTensePair verbTensePair = VerbTensePair.WouldBeButWas;
            var evaluator = new Evaluator<string>(
                new ExpectedClause<string>(verbTensePair, actual => Null.String.ToDebugString()),
                new ActualClause<string>(verbTensePair, actual => actual.ToDebugString()),
                s => string.IsNullOrEmpty(s) != collaboratingIs.Xray.Negated);
            return collaboratingIs.Xray.SpecificationBuilder.Specify(evaluator);
        }

        public static TSpecifies NullOrWhitespace<TSpecifies>(this IFluentIs<string, TSpecifies> collaboratingIs)
            where TSpecifies : class, ISpecification<string>
        {
            VerbTensePair verbTensePair = VerbTensePair.WouldBeButWas;
            var evaluator = new Evaluator<string>(
                new ExpectedClause<string>(verbTensePair, actual => Null.String.ToDebugString()),
                new ActualClause<string>(verbTensePair, actual => actual.ToDebugString()),
                string.IsNullOrWhiteSpace);
            return collaboratingIs.Xray.SpecificationBuilder.Specify(evaluator);
        }

        public static TSpecifies StringContaining<TSpecifies>(this IFluentIs<string, TSpecifies> collaboratingIs, string start)
            where TSpecifies : class, ISpecification<string>
        {
            Evaluator<string> evaluator = Expect<string>.ToBeStringContaining(start, collaboratingIs.Xray.Negated);
            TSpecifies specifies = collaboratingIs.Xray.SpecificationBuilder.Specify(evaluator);
            return specifies;
        }

        public static TSpecifies StringEndingWith<TSpecifies>(this IFluentIs<string, TSpecifies> collaboratingIs, string start)
            where TSpecifies : class, ISpecification<string>
        {
            Evaluator<string> evaluator = Expect<string>.ToBeStringEndingWith(start, collaboratingIs.Xray.Negated);
            TSpecifies specifies = collaboratingIs.Xray.SpecificationBuilder.Specify(evaluator);
            return specifies;
        }

        public static TSpecifies StringStartingWith<TSpecifies>(this IFluentIs<string, TSpecifies> collaboratingIs, string start)
            where TSpecifies : class, ISpecification<string>
        {
            Evaluator<string> evaluator = Expect<string>.ToBeStringStartingWith(start, collaboratingIs.Xray.Negated);
            TSpecifies specifies = collaboratingIs.Xray.SpecificationBuilder.Specify(evaluator);
            return specifies;
        }
    }
}
